/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProjetoView.java
 *
 * Created on 28/10/2011, 04:31:06
 */
package br.com.geftu.view;

import br.com.geftu.HibernateUtil.HibernateUtil;
import br.com.geftu.controle.ArrayListComboBoxModel;
import br.com.geftu.util.AutoCompletion;
import br.com.geftu.dao.DAO;
import br.com.geftu.model.Desenvolvedor;
import br.com.geftu.model.Funcao;
import br.com.geftu.model.Participa;
import br.com.geftu.model.Projeto;
import br.com.geftu.util.MaskF;
import java.awt.HeadlessException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.hibernate.Session;



/**
 *
 * @author jorgenei
 */
public final class ParticipaView extends javax.swing.JFrame {
List<Participa> lista_participa = new ArrayList();
List<Desenvolvedor> lista_desenvolvedor = new ArrayList();
List<Projeto> lista_projeto = new ArrayList();
List<Funcao> lista_funcao = new ArrayList();

Integer posicao_atual = 0;
String ordem = "order by idpart";
String listar = "from Participa ";

    /** Creates new form ProjetoView */
    public ParticipaView() {
        initComponents();       
        preencherJtable();    
        popularcombobox();                 
        puxaTabela();
    }
       

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupordenar = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        tf_pesquisa = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        rb_desenvolvedor = new javax.swing.JRadioButton();
        rb_projeto = new javax.swing.JRadioButton();
        rb_codigo = new javax.swing.JRadioButton();
        jButton4 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        tf_codigo = new java.awt.TextField();
        cb_projeto = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        cb_desenvolvedor = new javax.swing.JComboBox();
        cb_funcao = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tf_dtinicial = tf_dtinicial = new JFormattedTextField(MaskF.mascara("data"));
        jLabel10 = new javax.swing.JLabel();
        tf_dtfinal = tf_dtfinal = new JFormattedTextField(MaskF.mascara("data"));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cadastro Participações");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setName("jPanel1"); // NOI18N

        tf_pesquisa.setName("tf_pesquisa"); // NOI18N
        tf_pesquisa.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tf_pesquisaFocusGained(evt);
            }
        });
        tf_pesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tf_pesquisaKeyPressed(evt);
            }
        });

        jLabel7.setText("Pesquisa:");
        jLabel7.setName("jLabel7"); // NOI18N

        jButton1.setText("Novo");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Salvar");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Excluir");
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel4.setBackground(new java.awt.Color(204, 255, 153));
        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setName("jPanel4"); // NOI18N

        jLabel8.setText("Ordenar:");
        jLabel8.setName("jLabel8"); // NOI18N

        rb_desenvolvedor.setBackground(new java.awt.Color(204, 255, 153));
        groupordenar.add(rb_desenvolvedor);
        rb_desenvolvedor.setText("Desenvolvedor");
        rb_desenvolvedor.setName("rb_desenvolvedor"); // NOI18N
        rb_desenvolvedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_desenvolvedorActionPerformed(evt);
            }
        });

        rb_projeto.setBackground(new java.awt.Color(204, 255, 153));
        groupordenar.add(rb_projeto);
        rb_projeto.setText("Projeto");
        rb_projeto.setName("rb_projeto"); // NOI18N
        rb_projeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_projetoActionPerformed(evt);
            }
        });

        rb_codigo.setBackground(new java.awt.Color(204, 255, 153));
        groupordenar.add(rb_codigo);
        rb_codigo.setSelected(true);
        rb_codigo.setText("Código");
        rb_codigo.setName("rb_codigo"); // NOI18N
        rb_codigo.setVerifyInputWhenFocusTarget(false);
        rb_codigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_codigoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addGap(6, 6, 6)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rb_desenvolvedor)
                    .addComponent(rb_projeto)
                    .addComponent(rb_codigo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rb_codigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rb_projeto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rb_desenvolvedor)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jButton4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton4.setText("Fechar");
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(tf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addGap(41, 41, 41)
                        .addComponent(jButton4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(tf_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2)
                            .addComponent(jButton3)
                            .addComponent(jButton4)))
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 520, 100));

        jPanel3.setName("jPanel3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Projeto", "Desenvolvedor", "Função", "Data Inicial"
            }
        ));
        jTable1.setToolTipText("");
        jTable1.setCellSelectionEnabled(true);
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel3.setText("Nome Projeto:");
        jLabel3.setName("jLabel3"); // NOI18N

        tf_codigo.setEnabled(false);
        tf_codigo.setName("tf_codigo"); // NOI18N

        cb_projeto.setEditable(true);
        cb_projeto.setName("cb_projeto"); // NOI18N
        cb_projeto.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cb_projetoItemStateChanged(evt);
            }
        });
        cb_projeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_projetoActionPerformed(evt);
            }
        });
        cb_projeto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                cb_projetoFocusLost(evt);
            }
        });
        cb_projeto.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                cb_projetoInputMethodTextChanged(evt);
            }
        });
        cb_projeto.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                cb_projetoPropertyChange(evt);
            }
        });
        cb_projeto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cb_projetoKeyReleased(evt);
            }
        });
        cb_projeto.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                cb_projetoVetoableChange(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_projeto, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addComponent(jLabel3))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(cb_projeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        AutoCompletion.enable(cb_projeto);

        jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel5.setName("jPanel5"); // NOI18N

        jLabel6.setText("Desenvolvedor:");
        jLabel6.setName("jLabel6"); // NOI18N

        cb_desenvolvedor.setEditable(true);
        cb_desenvolvedor.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        cb_desenvolvedor.setName("cb_desenvolvedor"); // NOI18N
        cb_desenvolvedor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cb_desenvolvedorItemStateChanged(evt);
            }
        });
        cb_desenvolvedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_desenvolvedorActionPerformed(evt);
            }
        });
        cb_desenvolvedor.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                cb_desenvolvedorFocusLost(evt);
            }
        });

        cb_funcao.setEditable(true);
        cb_funcao.setName("cb_funcao"); // NOI18N

        jLabel5.setText("Função:");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel9.setText("Data Inicial:");
        jLabel9.setName("jLabel9"); // NOI18N

        tf_dtinicial.setName("tf_dtinicial"); // NOI18N

        jLabel10.setText("Data Final:");
        jLabel10.setName("jLabel10"); // NOI18N

        tf_dtfinal.setName("tf_dtfinal"); // NOI18N
        tf_dtfinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_dtfinalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(cb_desenvolvedor, 0, 400, Short.MAX_VALUE)
                        .addGap(28, 28, 28))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(cb_funcao, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_dtinicial, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                .addGap(27, 27, 27)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tf_dtfinal, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(70, 70, 70))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cb_desenvolvedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cb_funcao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_dtinicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(tf_dtfinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        AutoCompletion.enable(cb_desenvolvedor);
        AutoCompletion.enable(cb_funcao);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 518, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 92, 520, -1));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-558)/2, (screenSize.height-520)/2, 558, 520);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        jTable1.setVisible(true);
        try
        {    
           JOptionPane.showMessageDialog(null, cb_projeto.getSelectedItem());
            JOptionPane.showMessageDialog(null, cb_desenvolvedor.getSelectedItem());
           JOptionPane.showMessageDialog(null, cb_funcao.getSelectedItem());
           
         Participa participa = new Participa();

         if(tf_codigo.getText().equals(""))
         {
             participa.setProjeto((Projeto)cb_projeto.getSelectedItem());
             participa.setDesenvolvedor((Desenvolvedor)cb_desenvolvedor.getSelectedItem());
             participa.setFuncao((Funcao)cb_funcao.getSelectedItem());
             participa.setDtinicial(tf_dtinicial.getText());
             participa.setDtfinal(tf_dtfinal.getText());
             DAO objdao = new DAO(participa);
             objdao.insere();
         }
         else
         {             
             String alterar = "Tem certeza de que deseja alterar o registro?";
             int opcao_escolhida = JOptionPane.showConfirmDialog(null, alterar,"Exclusão ",JOptionPane.YES_OPTION);
             if (opcao_escolhida == JOptionPane.YES_OPTION)
             {
             participa.setIdpart(Integer.parseInt(tf_codigo.getText()));
             participa.setDesenvolvedor((Desenvolvedor)cb_desenvolvedor.getSelectedItem());                          
             participa.setProjeto((Projeto)cb_projeto.getSelectedItem());             
             JOptionPane.showMessageDialog(null, cb_desenvolvedor.getSelectedItem());
             participa.setFuncao((Funcao)cb_funcao.getSelectedItem());
             participa.setDtinicial(tf_dtinicial.getText());
             participa.setDtfinal(tf_dtfinal.getText());
             JOptionPane.showMessageDialog(null, participa.getIdpart()+" "+" "+participa.getDesenvolvedor()+" "+participa.getProjeto()+" "+participa.getFuncao()+" "+participa.getDtinicial()+" "+participa.getDtfinal());
             DAO objdao = new DAO(participa);
             objdao.insere();

             }
             
         }
         preencherJtable();
         popularcombobox();
         puxaTabela();

        }
        catch(HeadlessException | NumberFormatException erro)
        {
             JOptionPane.showMessageDialog(null,"Erro na insersão : "+erro);
        }// TODO add your handling code here:        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       jTable1.setVisible(false);
       tf_codigo.setText("");
       cb_projeto.setSelectedItem(null);
       cb_desenvolvedor.setSelectedItem(null);
       cb_funcao.setSelectedItem(null);
       cb_projeto.requestFocus();
       Date data = new Date(System.currentTimeMillis());
       SimpleDateFormat formatarDate = new SimpleDateFormat("dd/MM/YYYY");
       tf_dtinicial.setText(formatarDate.format(data));
       tf_dtfinal.setText(null);
       
       
    }//GEN-LAST:event_jButton1ActionPerformed

    private void rb_desenvolvedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_desenvolvedorActionPerformed
       ordem = "order by desenvolvedor.nome".toString();
       preencherJtable();
    }//GEN-LAST:event_rb_desenvolvedorActionPerformed

    private void rb_projetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_projetoActionPerformed
       ordem = "order by projeto.nomeprojeto".toString();        
       preencherJtable();
    }//GEN-LAST:event_rb_projetoActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        int linha = jTable1.getSelectedRow();
        cb_projeto.setSelectedItem(jTable1.getValueAt(linha, 1));
        cb_desenvolvedor.setSelectedItem(jTable1.getValueAt(linha, 2));        
        cb_funcao.setSelectedItem(jTable1.getValueAt(linha, 3));
        Participa participa = new Participa();
        participa = (Participa) jTable1.getValueAt(linha, 0);
        tf_codigo.setText(""+participa.getIdpart());
        tf_dtinicial.setText(participa.getDtinicial());
        tf_dtfinal.setText(participa.getDtfinal());
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        String excluir = "Tem certeza de que deseja excluir a participação "+tf_codigo.getText()+"?";
        int opcao_escolhida = JOptionPane.showConfirmDialog(null, excluir,"Exclusão ",JOptionPane.YES_OPTION);
        if (opcao_escolhida == JOptionPane.YES_OPTION)
        {
            try
            {
             Participa participa = new Participa();  
             participa.setIdpart(Integer.parseInt(tf_codigo.getText()));
             participa.setProjeto((Projeto)cb_projeto.getSelectedItem());
             participa.setDesenvolvedor((Desenvolvedor)cb_desenvolvedor.getSelectedItem());
             participa.setFuncao((Funcao)cb_funcao.getSelectedItem());
             participa.setDtinicial(tf_dtinicial.getText());
             participa.setDtfinal(tf_dtfinal.getText());
             JOptionPane.showMessageDialog(null, tf_codigo.getText());
             DAO objdao = new DAO(participa);
             objdao.excluir();
             preencherJtable();
            }
            catch(NumberFormatException | HeadlessException erro)
            {
                 JOptionPane.showMessageDialog(null,"Erro na insersão : "+erro);
            }
        } else
            JOptionPane.showMessageDialog(null,"Registro não excluído.");
    }
        // TODO add your handling code here:        // TODO add your handling code here:}//GEN-LAST:event_jButton3ActionPerformed

        private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
            encerrar();
            // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        encerrar();        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosed

    private void tf_pesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_pesquisaKeyPressed
        listar = "from Participa as participa where upper(participa.desenvolvedor.nome) like '%"+tf_pesquisa.getText().toUpperCase()+"%' or upper(participa.projeto.nomeprojeto) like '%"+tf_pesquisa.getText().toUpperCase()+"%'"; 
        preencherJtable();        // TODO add your handling code here:
    }//GEN-LAST:event_tf_pesquisaKeyPressed

    private void rb_codigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_codigoActionPerformed
        ordem = "order by idpart";
        preencherJtable();
        // TODO add your handling code here:
    }//GEN-LAST:event_rb_codigoActionPerformed
  // }
    private void cb_desenvolvedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_desenvolvedorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cb_desenvolvedorActionPerformed

    private void cb_projetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_projetoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cb_projetoActionPerformed

private void tf_dtfinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_dtfinalActionPerformed

}//GEN-LAST:event_tf_dtfinalActionPerformed

    private void tf_pesquisaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tf_pesquisaFocusGained
         jTable1.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_pesquisaFocusGained

    private void cb_projetoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cb_projetoFocusLost
    
    }//GEN-LAST:event_cb_projetoFocusLost

    private void cb_desenvolvedorFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cb_desenvolvedorFocusLost

    }//GEN-LAST:event_cb_desenvolvedorFocusLost

    private void cb_projetoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cb_projetoItemStateChanged
    }//GEN-LAST:event_cb_projetoItemStateChanged

    private void cb_projetoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cb_projetoKeyReleased
        if(tf_codigo.getText().trim().equals("")){
          Projeto projeto = new Projeto();
          projeto = (Projeto)cb_projeto.getSelectedItem();      
          JOptionPane.showMessageDialog(null, projeto.getDtfinal().toString());    
        }        // TODO add your handling code here:
    }//GEN-LAST:event_cb_projetoKeyReleased

    private void cb_projetoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_cb_projetoPropertyChange
                // TODO add your handling code here:
    }//GEN-LAST:event_cb_projetoPropertyChange

    private void cb_projetoVetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {//GEN-FIRST:event_cb_projetoVetoableChange

    }//GEN-LAST:event_cb_projetoVetoableChange

    private void cb_projetoInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_cb_projetoInputMethodTextChanged

    }//GEN-LAST:event_cb_projetoInputMethodTextChanged

    private void cb_desenvolvedorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cb_desenvolvedorItemStateChanged
     try
     {
        if(cb_projeto.getSelectedIndex()>-1){
            
            if (tf_codigo.getText().trim().equals("")) {
            Projeto projeto = new Projeto();
            projeto = (Projeto) cb_projeto.getSelectedItem();
            tf_dtfinal.setText(projeto.getDtfinal());
            }else{
                return;
            }
            
        }
         
     }
     catch(RuntimeException e){
         e.printStackTrace();
         JOptionPane.showMessageDialog(null, "teste");
         
     }
    }//GEN-LAST:event_cb_desenvolvedorItemStateChanged
           
    /**
     * @param args the command line arguments
     */
        //xx1
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ParticipaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ParticipaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ParticipaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ParticipaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ParticipaView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cb_desenvolvedor;
    private javax.swing.JComboBox cb_funcao;
    private javax.swing.JComboBox cb_projeto;
    private javax.swing.ButtonGroup groupordenar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JRadioButton rb_codigo;
    private javax.swing.JRadioButton rb_desenvolvedor;
    private javax.swing.JRadioButton rb_projeto;
    private java.awt.TextField tf_codigo;
    private javax.swing.JTextField tf_dtfinal;
    private javax.swing.JFormattedTextField tf_dtinicial;
    private javax.swing.JTextField tf_pesquisa;
    // End of variables declaration//GEN-END:variables

public void popularcombobox()
{
    Session sessao = HibernateUtil.getSession();
    lista_desenvolvedor =   sessao.createQuery("from Desenvolvedor order by nome").list();
    
    ArrayListComboBoxModel modelolista = new ArrayListComboBoxModel(lista_desenvolvedor);
    cb_desenvolvedor.setModel(modelolista);
    
    lista_projeto = sessao.createQuery("from Projeto order by nomeprojeto").list();
    modelolista = new ArrayListComboBoxModel(lista_projeto);
    cb_projeto.setModel(modelolista);
    
    lista_funcao = sessao.createQuery("from Funcao order by funcao").list();
    modelolista = new ArrayListComboBoxModel(lista_funcao);
    cb_funcao.setModel(modelolista);
}

public void puxaTabela(){
      if(! lista_participa.isEmpty())
              {
               Participa participa = new Participa();
               participa = lista_participa.get(0);  
               tf_codigo.setText(""+participa.getIdpart());
               cb_desenvolvedor.setSelectedItem(participa.getDesenvolvedor());
               cb_projeto.setSelectedItem(participa.getProjeto());
               cb_funcao.setSelectedItem(participa.getFuncao());
               tf_dtinicial.setText(participa.getDtinicial());
               tf_dtfinal.setText(participa.getDtfinal());
              }
}

public void preencherJtable()
    {
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(10);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(140);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(20);
       
        DefaultTableModel modelo = (DefaultTableModel)jTable1.getModel();
        modelo.setNumRows(0);
        Participa participa = new Participa();
        
       try
        {
            Session sessao = HibernateUtil.getSession();
            

            lista_participa = sessao.createQuery(listar+ordem).list();

                for(int i=0;i< lista_participa.size();i++)
                {
                    participa  = lista_participa.get(i);
                    modelo.addRow(new Object [] {participa,participa.getProjeto(), participa.getDesenvolvedor(), participa.getFuncao(),participa.getDtinicial(),participa.getDtfinal()});                    
                }
                        
         }
        catch(Exception erro)
        {
             JOptionPane.showMessageDialog(null,"Erro na insersão : "+erro);
        }
       
        
    }
public void encerrar(){
    setVisible(false);
    RelatoView.getInstance().setVisible(true);
}

}
